import { API_LIST } from '../../../Api/Api'
import { commonTableList, BuiltInData } from '../Common/common'
import { AddDataButton, ModDataButton, DelDataButton, OrdinaryQRCodeButton, MoreActionsButton } from '../Common/options'

export const BeamProduceRecord = async ({ url, OptionsEvent, ClientData, Permission }) => {
    let data = {
        pageSize: 10,
        params: { pageIndex: 1 },
        get: API_LIST()[`get${url}`],
        added: `pos${url}`,
        modify: `put${url}`,
        delete: `del${url}`,
        CascaderInIt: { dataIndex: 'beamSelect', arr: ['bridgeName', 'partName', 'beamNo'] },
        options: [
            Permission.findIndex(v => v.uuid === '3c618336-63fd-471d-98b7-df1dcf04a8ed') !== -1 && (
                <AddDataButton OptionsEvent={OptionsEvent} type="primary" icon="add" title="新增" />
            ),
        ],
        columns: [
            commonTableList.uuid,
            { ...commonTableList.SearchSort, selectType: 'BeamProduceRecord' },
            { ...commonTableList.organizationUuid, valueEnum: ClientData.organization },
            {
                dataIndex: 'produceDate',
                title: '生产日期',
                valueType: 'Date',
                rules: true,
                width: 220,
            },
            {
                dataIndex: 'bridgeName',
                title: '桥名称',
                valueType: 'select',
                valueEnum: {},
                hideInAdded: true,
                hideInModify: true,
                width: 220,
            },
            {
                dataIndex: 'part',
                title: '部位',
                valueType: 'select',
                valueEnum: BuiltInData.part,
                hideInAdded: true,
                hideInModify: true,
                width: 220,
            },
            {
                dataIndex: 'beamNo',
                title: '梁号',
                valueType: 'input',
                hideInAdded: true,
                hideInModify: true,
                hideInSearch: true,
                width: 220,
            },

            {
                dataIndex: 'beamUuid',
                title: '梁号',
                valueType: 'hidden',
                hideInTable: true,
                hideInSearch: true,
                width: 150,
            },
            {
                dataIndex: 'beamSelect',
                title: '梁号',
                valueType: 'beamCascader',
                rules: true,
                hideInTable: true,
                hideInSearch: true,
                width: 150,
            },

            {
                dataIndex: 'concreteStrength1',
                title: '强度1',
                valueType: 'inputNumber',
                width: 150,
            },
            {
                dataIndex: 'concreteStrength2',
                title: '强度2',
                valueType: 'inputNumber',
                width: 150,
            },
            {
                dataIndex: 'concreteStrength3',
                title: '强度3',
                valueType: 'inputNumber',
                width: 150,
            },

            {
                dataIndex: 'auditStatus',
                title: '状态',
                valueType: 'select',
                valueEnum: BuiltInData.auditStatus,
                rules: true,
                hideInAdded: true,
                hideInModify: true,
                hideInTable: true,
                width: 150,
            },
            // 通用部分
            {
                dataIndex: 'BeamTypeUuid',
                title: '梁类别',
                valueType: 'select',
                valueEnum: {},
                hideInAdded: true,
                hideInModify: true,
                hideInTable: true,
            },
            {
                dataIndex: 'ProcessUuid',
                title: '施工工序',
                valueType: 'select',
                valueEnum: {},
                hideInAdded: true,
                hideInModify: true,
                hideInTable: true,
            },

            commonTableList.BeginProduce,
            commonTableList.EndProduce,
            commonTableList.createUserName,
            commonTableList.createTime,
            commonTableList.updateUserName,
            commonTableList.updateTime,
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 320,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    const { uuid, beamUuid } = record
                    return [
                        Permission.findIndex(v => v.uuid === '670b366e-fc6e-45c9-b3a1-7370e5c57baa') !== -1 && (
                            <ModDataButton OptionsEvent={OptionsEvent} key="modify" title="修改" data={record} />
                        ),
                        Permission.findIndex(v => v.uuid === 'd060d2dc-bf77-445f-a47a-330866dd9591') !== -1 && (
                            <OrdinaryQRCodeButton
                                key="qrcode"
                                title="二维码"
                                OptionsEvent={OptionsEvent}
                                data={{ url: `${window.location.origin}/Qrcode/${beamUuid}` }}
                            />
                        ),
                        Permission.findIndex(v => v.uuid === '3089c162-8c0b-4b5e-a8aa-562130ca2205') !== -1 && (
                            <DelDataButton OptionsEvent={OptionsEvent} key="del" title="删除" url={url} uuid={uuid} />
                        ),
                        <MoreActionsButton
                            key="more"
                            title="更多操作"
                            data={{
                                record,
                                Permission,
                                OptionsEvent,
                                header: data.columns,
                                BeamProduceRecordDetail: {
                                    type: 'OpenTwoRouter',
                                    smallTitle: '梁生产工序',
                                    modal: 'TableList',
                                },
                                BeamProduceRecordPersonGroup: {
                                    type: 'OpenTwoRouter',
                                    smallTitle: '梁生产人员',
                                    modal: 'TableList',
                                },
                                BeamQualityReport: {
                                    type: 'OpenTwoRouter',
                                    smallTitle: '梁质检报告',
                                    modal: 'TableList',
                                },
                            }}
                            items={[
                                Permission.findIndex(v => v.uuid === '3abb1a60-0cd3-4e1c-b51d-a5bde93aa63c') !== -1 && {
                                    key: 'BeamProduceRecordDetail',
                                    label: '梁生产工序',
                                },
                                Permission.findIndex(v => v.uuid === '4fda3490-77f9-460f-9a83-149547f11ca1') !== -1 && {
                                    key: 'BeamProduceRecordPersonGroup',
                                    label: '梁生产人员',
                                },
                                Permission.findIndex(v => v.uuid === 'e436235a-97e7-4836-b22c-27622faea437') !== -1 && {
                                    key: 'BeamQualityReport',
                                    label: '梁质检报告',
                                },
                            ]}
                        />,
                    ]
                },
            },
        ],
    }
    return data
}
